package cevent.source.cloudcenter.source.config;/**
 * Created by Cevent on 2021/4/24.
 */

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author cevent
 * @description springMVC静态资源配置，暴露外部文件目录
 * @date 2021/4/24 16:55
 */
@Configuration
public class SourceStaticConfig implements WebMvcConfigurer {
    //注入properties中的file配置
    @Value("${file.targetPath}")
    private String FILE_TARGET_PATH;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** pathPatterns:所有带/f ...**的请求，为静态资源请求=D:/DEV_CODE/Intelligy_idead_code/upload-file/
         *  请求时保存的去全路径：String fullPath="D:/DEV_CODE/Intelligy_idead_code/upload-file/source/"+fileKey+"-"+fileName;
         *  访问图片全路径(加入请求的source目录)：http://localhost:8803/source/f/source/sourcexxx.jpg
         */
        registry.addResourceHandler("/f/**").addResourceLocations("file:"+FILE_TARGET_PATH);
    }

}
